// 判断一下本地存储为空的时候，不让进入本页面
if (localStorage.getItem("token") == null) {
    window.location.href = "./login.html"
}

//获取用户基本信息
let layer = layui.layer
function genInfo() {
    $.ajax({
        url: "/my/userinfo",
        // 去公共.js中查找
        // headers: {
        //     Authorization: localStorage.getItem("token")
        // },
        success: function (res) {
            // console.log(res.data);
            if (res.status == 0) {
                let obj = res.data
                if (obj.user_pic != null) {
                    $(".userinfo img").show().prop("src", obj.user_pic)
                }
                else if (obj.nickname != "") {
                    let l = obj.nickname.substr(0, 1).toUpperCase();
                    $(".userinfo .avatar").css("display", "inline-block").text(l)
                } else if (obj.username != "") {
                    let l = obj.username.substr(0, 1).toUpperCase();
                    $(".userinfo .avatar").css("display", "inline-block").text(l)
                }
            }


        },
        // 去公共.js中查找
        // complete: function (res) {
        //     let obj = JSON.parse(res.responseText)
        //     if (obj.status == 1 && obj.message == "身份认证失败") {
        //         window.location.href = "./login.html"
        //         localStorage.removeItem("token")
        //     }
        // }
    })

}
genInfo()
$("#logout").on("click", function () {
    window.location.href = "./login.html"
    localStorage.removeItem("token")
})